.TH std::function::target_type 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::function::target_type \- std::function::target_type

.SH Synopsis
   const std::type_info& target_type() const noexcept;  \fI(since C++11)\fP

   Returns the type of the stored function.

.SH Parameters

   \fI(none)\fP

.SH Return value

   typeid(T) if the stored function has type T, otherwise typeid(void)

.SH Example


// Run this code

 #include <functional>
 #include <iostream>

 int f(int a) { return -a; }
 void g(double) {}
 int main()
 {
     // fn1 and fn2 have the same type, but their targets do not
     std::function<int(int)> fn1(f),
                             fn2([](int a) {return -a;});
     std::cout << fn1.target_type().name() << '\\n'
               << fn2.target_type().name() << '\\n';

     // since C++17 deduction guides (CTAD) can avail
     std::cout << std::function{g}.target_type().name() << '\\n';
 }

.SH Possible output:

 PFiiE
 Z4mainEUliE_
 PFvdE

.SH See also

   target    obtains a pointer to the stored target
             \fI(public member function)\fP
   typeid    Queries information of a type, returning a std::type_info object
             representing the type.
             contains some type's information, generated by the implementation.
   type_info This is the class returned by the typeid operator.
             \fI(class)\fP
